package com.zyh.poly;

import com.zyh.domain.Animal;
import com.zyh.domain.Cat;
import com.zyh.domain.Dog;

public class PolyDemo1 {
    public static void main(String[] args) {
        Dog dog = new Dog();
        Cat cat = new Cat();
        method(dog);
        System.out.println("===========================================");
        method(cat);
        Animal animal = m1(dog);
        System.out.println(animal);
    }

    public static void method(Animal animal) {
        if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.eat();
            dog.lookHome();
        }
        if (animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.eat();
            cat.catchMouse();
        }
    }

    public static Animal m1(Animal animal) {
        return new Dog();
    }
}
